from flask import Flask, config, request
from flask_socketio import SocketIO

from tvService.signallingService import signallingService
from utils.loggerUtils import loggerUtils

app = Flask(__name__,static_folder='staticResources', static_url_path='/resources')
app.config.from_object(config)
#增加跨域请求
socketio = SocketIO(app,cors_allowed_origins='*')


sigService=signallingService()

#加入房间
@socketio.on('join')
def enterRoom(roomId):

    sid=request.sid

    loggerUtils.info("enterRoom param:sid="+sid+",roomId="+roomId)

    sigService.enterRoom(sid,roomId)


@socketio.on('message')
def transferMsg(roomId,data):
    # loggerUtils.info("transferMsg param:roomId="+roomId+",data="+str(data))

    sigService.transferMsg(roomId,data);

@socketio.on('leave')
def leaveRoom(roomId):

    sid=request.sid

    loggerUtils.info("enterRoom param:sid="+sid+",roomId="+roomId)

    sigService.leaveRoom(sid,roomId)



if __name__ == "__main__":
    loggerUtils.info("start service......")
    socketio.run(app)


##配置nginx
#https://blog.csdn.net/hfismyangel/article/details/82758629


